package utils;

import java.util.HashMap;
import java.util.Vector;

import datastructures.*;

public class ArgMax {

	public static Pair<String,Double> argmax(HashMap<String, Double> elements)
	{
		Pair<String,Double> max = null;
		for (String key : elements.keySet())
		{
			if (max == null) max = new Pair<String,Double>(key,elements.get(key));
			if (max.second < elements.get(key).doubleValue())
				max = new Pair<String,Double>(key,elements.get(key));
		}
		return max;
	}
	
	
	// returns, in a vector format of top n arguments, or top k if only k elements in it.
	public static Vector<Pair<String,Double>> topArgmax(HashMap<String, Double> elements, int n)
	{
		Vector<Pair<String,Double>> returner = new Vector<Pair<String,Double>>();
		for (int i = 0; i < n; i++)
		{
			Pair<String,Double> curr = argmax(elements);
			if (curr == null) return returner;
			elements.remove(curr.first);
			returner.add(curr);
		}
		return returner;
	}
}
